dev_deps: true,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
+ spec: None,
},
};
Compile a local package and all of its dependencies
Usage:
- cargo build [options]
+ cargo build [options] [<spec>]
Options:
-h, --help Print this message
--target TRIPLE Build for the target triple
--manifest-path PATH Path to the manifest to compile
-v, --verbose Use verbose output
+
+If <spec> is given, then only the package specified will be build (along with
+all its dependencies). If <spec> is not given, then the current package will be
+built.
+
+For more information about the format of <spec>, see `cargo help pkgid`.
", flag_jobs: Option<uint>, flag_target: Option<String>,
- flag_manifest_path: Option<String>, flag_features: Vec<String>)
+ flag_manifest_path: Option<String>, flag_features: Vec<String>,
+ arg_spec: Option<String>)
pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-build; args={}", os::args());
dev_deps: false,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
+ spec: options.arg_spec.as_ref().map(|s| s.as_slice()),
};
ops::compile(&root, &mut opts).map(|_| None).map_err(|err| {
dev_deps: false,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
+ spec: None,
},
};
dev_deps: true,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
+ spec: None,
};
let err = try!(ops::run(&root, &mut compile_opts,
dev_deps: true,
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
+ spec: None,
},
};
pub dev_deps: bool,
pub features: &'a [String],
pub no_default_features: bool,
+ pub spec: Option<&'a str>,
}
pub fn compile(manifest_path: &Path,
options: &mut CompileOptions)
-> CargoResult<ops::Compilation> {
- let CompileOptions { env, ref mut shell, jobs, target,
+ let CompileOptions { env, ref mut shell, jobs, target, spec,
dev_deps, features, no_default_features } = *options;
let target = target.map(|s| s.to_string());
let features = features.iter().flat_map(|s| {
debug!("packages={}", packages);
- let targets = package.get_targets().iter().filter(|target| {
+ let to_build = match spec {
+ Some(spec) => {
+ let pkgid = try!(resolve_with_overrides.query(spec));
+ packages.iter().find(|p| p.get_package_id() == pkgid).unwrap()
+ }
+ None => &package,
+ };
+
+ let targets = to_build.get_targets().iter().filter(|target| {
match env {
// doc-all == document everything, so look for doc targets
"doc" | "doc-all" => target.get_profile().get_env() == "doc",
let mut config = try!(Config::new(*shell, jobs, target));
try!(scrape_target_config(&mut config, &user_configs));
- try!(ops::compile_targets(env.as_slice(), targets.as_slice(), &package,
+ try!(ops::compile_targets(env.as_slice(), targets.as_slice(), to_build,
&PackageSet::new(packages.as_slice()),
&resolve_with_overrides, &sources,
&mut config))
debug!("compile_targets; targets={}; pkg={}; deps={}", targets, pkg, deps);
let dest = uniq_target_dest(targets);
- let host_layout = Layout::new(pkg, None, dest);
+ let root = deps.iter().find(|p| p.get_package_id() == resolve.root()).unwrap();
+ let host_layout = Layout::new(root, None, dest);
let target_layout = config.target().map(|target| {
- layout::Layout::new(pkg, Some(target), dest)
+ layout::Layout::new(root, Some(target), dest)
});
let mut cx = try!(Context::new(env, resolve, sources, deps, config,
// particular package. No actual work is executed as part of this, that's
// all done later as part of the `execute` function which will run
// everything in order with proper parallelism.
+ let mut dep_pkgids = HashSet::new();
+ each_dep(pkg, &cx, |dep| {
+ dep_pkgids.insert(dep.get_package_id().clone());
+ });
for dep in deps.iter() {
if dep == pkg { continue }
+ if !dep_pkgids.contains(dep.get_package_id()) { continue }
// Only compile lib targets for dependencies
let targets = dep.get_targets().iter().filter(|target| {
try!(compile(targets.as_slice(), dep, &mut cx, &mut queue));
}
- cx.primary();
+ if pkg.get_package_id() == resolve.root() {
+ cx.primary();
+ }
try!(compile(targets, pkg, &mut cx, &mut queue));
// Now that we've figured out everything that we're going to do, do it!
assert_that(
cargo::util::process(p.bin("foo")),
execs().with_stdout("test passed\n"));
+
+ println!("cleaning");
+ assert_that(p.process(cargo_dir().join("cargo")).arg("clean"),
+ execs().with_stdout(""));
+ println!("building baz");
+ assert_that(p.process(cargo_dir().join("cargo")).arg("build").arg("baz"),
+ execs().with_stdout(format!("{} baz v0.5.0 ({})\n",
+ COMPILING, p.url())));
+ println!("building foo");
+ assert_that(p.process(cargo_dir().join("cargo")).arg("build").arg("foo"),
+ execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, p.url(),
+ COMPILING, p.url())));
})
test!(cargo_compile_with_root_dev_deps {